﻿HBArray = function(name) { //初始化属性
    this._name = name;      //对象名称
    this._mylist = []; //列表
};
HBArray.prototype = {
    version: '1.0.0',
    Author: 'hanbing81868164@163.com',

    //返回数数
    SetArray: function(newarray) {
        this._mylist = newarray;
    },

    //返回数数
    GetArray: function() {
        return this._mylist;
    },

    //清理数数
    ClearArray: function() {
        this._mylist = new Array();
    },

    //返回数数
    GetArrayToString: function() {
        return this._mylist.toString();
    },

    //返回数数
    GetArrayLength: function() {
        return this._mylist.length;
    },

    //返回数数
    GetArrayIndex: function(i_) {
        if (this._mylist.length > i_) {
            return this._mylist[i_];
        }
        return null;
    },

    //返回数数
    GetIndex: function(obj_) {
        if (this._mylist.length > 0) {
            for (var i = 0; i < this._mylist.length; i++) {
                if (this._mylist[i] == obj_) {
                    return i;
                }
            }
        }
        return null;
    },

    //判断是否存在于列表中
    InArray: function(obj_) {
        obj_ = this.GetObj(obj_);
        var rtf_ = false;
        if (this._mylist.length > 0) {
            for (var i = 0; i < this._mylist.length; i++) {
                if (this._mylist[i] == obj_) {
                    rtf_ = true;
                    break;
                }
            }
        }
        return rtf_;
    },

    //返回参数的小写
    GetObj: function(obj_) {
        if (typeof (obj_) == "string") {
            return obj_.toLowerCase();
        }
        return obj_;
    },

    //将图片添加到列表中
    AddArray: function(obj_) {
        obj_ = this.GetObj(obj_);
        if (this._mylist.length > 0) {
            var inimg_ = false;
            for (var i = 0; i < this._mylist.length; i++) {
                if (this._mylist[i] == obj_) {
                    inimg_ = true;
                    break;
                }
            }

            if (!inimg_) {
                this._mylist.push(obj_); //添加
            }
        }
        else {
            this._mylist.push(obj_); //添加
        }
    },

    //将图片从列表中删除
    DelArray: function(obj_) {
        obj_ = this.GetObj(obj_);
        if (this._mylist.length > 0) {
            if (this._mylist.length == 1 && this._mylist[0] == obj_) {
                this.ClearArray();
            }
            else {
                var inimg_ = -1;
                for (var i = 0; i < this._mylist.length; i++) {
                    if (this._mylist[i] == obj_) {
                        inimg_ = i;
                        break;
                    }
                }

                if (inimg_ != -1) {
                    this._mylist.splice(inimg_, 1); //删除数组项
                }
            }
        }
    },

    //删除数组里的项
    DelIndex: function(index_) {
        if (this._mylist.length > 0 && index_ < this._mylist.length) {
            this._mylist.splice(inimg_, 1); //删除数组项
        }
    }
};